<template>
  <FModal ref="FModal" @ok="close" @cancel="close" width="800">
    <el-table :data="viewAction.subFormButtonAction" height="100%"
              ref="viewActionsTable" stripe style="width: 100%">
      <el-table-column show-overflow-tooltip label="明细表名" min-width="180">
        <template #default="{row}">
          {{ getSubFormShowNameById(row.subFormId) }}
        </template>
      </el-table-column>

      <el-table-column show-overflow-tooltip label="插入行" min-width="180">
        <template #default="{row}">
          <el-checkbox v-model="row.defaultAddButtonAuth"
                       true-label="1" false-label="0"/>
        </template>
      </el-table-column>

      <el-table-column show-overflow-tooltip label="删除行" min-width="180">
        <template #default="{row}">
          <el-checkbox v-model="row.defaultRemoveButtonAuth"
                       true-label="1" false-label="0"/>
        </template>
      </el-table-column>

      <el-table-column show-overflow-tooltip label="最小行数" min-width="180">
        <template #default="{row}">
          <el-input-number v-model="row.defaultMinLines" :step="1" :min="0"/>
        </template>
      </el-table-column>
    </el-table>
  </FModal>
</template>

<script>
import {DefaultFormDefinition, DefaultViewAction} from '@/components/form/DefaultFormDefinition';
import FModal from '@/components/FModal/index.vue';
import {isEmpty} from '@/utils/CommonUtils';

export default {
  name: 'SubFormButtonActionConfiguration',
  components: {
    FModal
  },
  data() {
    return {
      viewAction: DefaultViewAction,
      formDefinition: DefaultFormDefinition,
    };
  },
  methods: {
    setData(viewAction, formDefinition) {
      this.$refs.FModal.open();
      this.viewAction = viewAction;
      this.formDefinition = formDefinition;
    },
    getSubFormShowNameById(subFormId) {
      let subForms = this.formDefinition.subForms;
      if (isEmpty(subForms)) return '';
      let subForm = subForms.find(f => f.id === subFormId);
      if (isEmpty(subFormId)) return '';
      return subForm.showName;
    },
    close() {
      this.$refs.FModal.close();
    },
  }
};
</script>
